<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>
<!DOCTYPE html>
<html>
<head>
	<title><spring:message code="message.jieSuan.jieSuanDanMingXi"/>    <spring:message code="message.listForm.weiShengJu"/></title>
	<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1><spring:message code="message.button.addDetail"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx }/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.jieSuan.jieSuanDan"/><spring:message code="message.jieSuan.guanLi"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.listForm.weiShengJu"/><spring:message code="message.jieSuan.jieSuanDan"/><spring:message code="message.jieSuan.guanLi"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.jieSuan.woDeJieSuanDan"/></a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="form-inline">
                
                 <div class="form-group form-group-xs">
                        <label for="name"><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <input class="form-control" type="text" id="hospName" placeholder="<spring:message code="message.listForm.tongYongMing"/>" maxlength="100" />
                    </div>
                    
                <div class="form-group form-group-xs">
                        <label for="name"><spring:message code="message.listForm.yaoPinBianMa"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <input class="form-control" type="text" id="hospCode" placeholder="<spring:message code="message.listForm.yaoPinBianMa"/>" maxlength="100" />
                    </div>
                   
                	
                    <button  id="selectWSJ"   type="button" class="btn btn-success btn-sm" onclick="gridSerch();"><spring:message code="message.button.seachSpacing"/></button>
                </div>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
		<div id="gridpage"></div>
		
		<div class=" box box-warning bottongroup">
			<button type="button" onclick="batchJoin();" class="btn btn-default btn-sm"><spring:message code="message.jieSuan.tianJiaSpacing"/></button>
			<a href="toSettlementSecondList.html" class="btn btn-default btn-sm"><spring:message code="message.button.getBackSpacing"/></a>
		</div>
		
    </section>

		<%@ include file="/WEB-INF/component/commonJS.jsp"%>
		<script type="text/javascript">
		
		//加载页面光标在名字框内，位于第一个
		   $("#hospName").focus();
		   
		 //绑定回车    id="selectWSJ"  
		   $('#hospName,#hospCode').bind('keydown', function(event) {
		       if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
		           $('#selectWSJ').click();
		       }
		   });
		 
		$(function () {
			
			jQuery("#gridlist").jqGrid({
    			url: "${ctx}/settlementFirst/getAddSecondDetailDataList.html?settlementId=${param.settlementId}",
    		    mtype: "POST",
    			datatype: "json",
    			autowidth: true,
    			shrinkToFit: false,
    			height: 270,
    		   	colNames:[ 
    		   	           '<spring:message code="message.jieSuan.jieSuanDan"/>id',
                          '<spring:message code="message.jieSuan.jieSuanDan"/><spring:message code="message.yanZheng.bianMa"/>',
                          '<spring:message code="message.jieSuan.jieSuanDan"/><spring:message code="message.listForm.mingCheng"/>',
    		   	           '<spring:message code="message.jieSuan.zongTiaoMuShu"/>',
    		   	           '<spring:message code="message.jieSuan.zongJinE"/>',
    		   	           '<spring:message code="message.listForm.yaoPinBianMa"/>',
    		   	           '<spring:message code="message.listForm.tongYongMing"/>',
    		   	           '<spring:message code="message.lable.remark"/>',
    		   	           '<spring:message code="message.jieSuan.tiJiaoRen"/>',
    		   	           '<spring:message code="message.jieSuan.tiJiaoShiJian"/>'
    		   	           ],
    		   	colModel:[
					{ name: 'settlementId', width:160,hidden:true,align:"center" ,sortable:false},
					{ name: 'settlementCode', width:160,salign:"center" ,sortable:false}, 
					{ name: 'settlementName', width:160,align:"left" ,sortable:false}, 
					{ name: 'totalOrders', width:80,align:"center" ,sortable:false},
					{ name: 'totalAmount', width:100,align:"right" ,sortable:false,
						formatter :function(val){
							return val.toFixed(2);
						}},
					{ name: 'hospCode', width:160,align:"center" ,sortable:false},      
					{ name: 'hospName', width:160,align:"left" ,sortable:false},      
					{ name: 'remarks', width:160,align:"left" ,sortable:false},       
					{ name: 'submitUser', width:160,align:"left" ,sortable:false},      
    				{ name: 'submitDatetime', width:160,align:"center" ,sortable:false}
    				
    		   	],
    			 rowNum: 20,
    		     rowList: [10, 20, 50, 100],
    		     rownumbers: true,
    		     pager: "#gridpage",
    		     viewrecords: true,
    		     multiselect: true, 
    		     caption: "<spring:message code="message.jieSuan.jieSuanDanMingXi"/><spring:message code="message.listForm.lieBiao"/>",
    		     //序号宽度自动变化
                 gridComplete:function(){
                     //序号列宽度自适应（参数为jqgridID）
                     autoRNWidth("gridlist");
                     //数据只有一条时默认选中（参数为jqgridID）
                     selectByOneData("gridlist");
                 },
    		     jsonReader: {
    		         repeatitems: false,
    		         id: "ids"
    		     }
    		});
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $(window).trigger("resize");
            
        });
			
	
		//查询
        function gridSerch() {
        	var hospCode = $.trim($("#hospCode").val());
        	var hospName = $.trim($("#hospName").val());
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{
    	        		"hospCode":hospCode,
    	        		"hospName":hospName,
    	        		},
    	        		page:1
    	    }).trigger("reloadGrid"); //重新载入  
    	}
		
      //添加
        function batchJoin(code){
      	 
          	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
      		if (rowIds.length <= 0) {
      			$.HN.message.alert("<spring:message code="message.HN.alert.pleaseSelectLine"/>", "<spring:message code="message.HN.alert.type"/>", "warn");
                return;
      		}
      		$.HN.message.confirm('<spring:message code="message.jieSuan.queDingJiaRuSuoXuanMa"/>', '', '').on(function (e) {
                if (e) {
      				var list = [];
      	    		for (var i=0; i<rowIds.length; i++) {
      	    			rowId = rowIds[i];
      	    			var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
      	    			list.push({"settlementId":rowdata.settlementId}); 
      	    		}
      	    		$.post("${ctx}/settlementFirst/addSecondDetail.html", {
      	    			"array" : json.jsonToString(list),"code":code,"settlementId":"${param.settlementId}"
      	    		}, function(result) {
      	    			if (result.success) {
      	    				gridSerch();
      	    				$.HN.message.alert("<spring:message code="message.HN.alert.success"/>", "<spring:message code="message.HN.alert.type"/>", "success");
      	    			} else {
      	    				if(result.code ==1){
      	    					batchJoin(1);
      	    				}
      	    				$.HN.message.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "<spring:message code="message.HN.alert.type"/>", "error");
      	    			}
      	    		}, "json")
      			}
      		});
          }
</script>
</body>
</html>